package com.etung.iot.demo.storage;

import com.etung.iot.demo.modles.RealData;
import com.etung.iot.demo.storage.conTriggerStorage.PreConditionStorageUtil;
import com.etung.iot.demo.storage.conTriggerStorage.PreTriggerStoreRule;
import com.etung.iot.demo.storage.constorage.ConditionStorageUtil;
import com.etung.iot.demo.storage.constorage.TriggerConditionStoreRule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class ConStorageSelector {
    @Autowired
    private ConditionStorageUtil conditionStorageUtil;
    @Autowired
    private TriggerConditionStoreRule triggerConditionStoreRule;
    @Autowired
    private PreTriggerStoreRule preTriggerStoreRule;
    @Autowired
    private PreConditionStorageUtil preConditionStorageUtil;

    @Value("${conStorage.type}")
    private int type;

    public void saveConditionRealData(RealData realData){
        if(type == 0){
            preTriggerStoreRule.saveTargetVariantValue(realData);
        }else{
            triggerConditionStoreRule.saveRealData(realData);
        }
    }

    public void removeConditionStorageRule(String imei){
        if(type == 0){
            preConditionStorageUtil.removeConditionStorageRule(imei);
        }else{
            conditionStorageUtil.removeConditionStorageRule(imei);
        }
    }
}
